package com.abigdreamer.im.client.module.main.search;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JList;
import javax.swing.ListCellRenderer;

import com.abigdreamer.im.client.module.main.headtree.NodeIcon;
import com.abigdreamer.im.client.module.vo.Cache;
import com.abigdreamer.im.client.module.vo.MsgUser;

class CellRenderer extends NodeIcon implements ListCellRenderer {
	
	private static final long serialVersionUID = 1L;
	
	MsgUser user;

	public CellRenderer() {
		setOpaque(true);
	}

	public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
		
		String userID = (String) value;
		if (value != null) {
			Cache cache = Cache.getInstance();
			MsgUser user = cache.getfriendMap().get(userID);

			this.user = user;
			String headImage = (String) user.getAttribute("headImage");
			setNodeInfo(headImage, user.isOnline(), 20);
			
			setText(user.getUserName() + "(" + userID + ")");
		}
		if (isSelected) {
			setBackground(list.getSelectionBackground());
			setForeground(list.getSelectionForeground());
		} else {
			setBackground(list.getBackground());
			setForeground(list.getForeground());

		}
		return this;
	}
}
